﻿#region 命名空间

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using WinnerCMS.BLL;
using WinnerCMS.Common;
using WinnerCMS.Model.Attribute;

#endregion

namespace WinnerCMS.WebUI.Admin.GuestBook
{
    [Access("265002")]
    public partial class Setting : WebFactory.PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ReadGuestBookConfigXML();
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            var ErrMsg = "";
            try
            {
                WriteGuestBookConfigXML();
            }
            catch (Exception Ex)
            {
                ErrMsg = Ex.Message;
            }
            if (ErrMsg.Length == 0)
            {
                MsgBox.Message("操作完成！", this.UpdatePanel1);
            }
            else
            {
                MsgBox.Message(ErrMsg, this.UpdatePanel1);
            }
        }

        #region GuestBook

        private void ReadGuestBookConfigXML()
        {
            var config = CMSConfig.Instance();
            this.txtGuestBookName.Text = config.GuestBook.Name;
            this.txtGBPageSize.Text = config.GuestBook.PageSize.ToString();
            this.cbkShowGB.Checked = config.GuestBook.ShowGB;
            this.cbkGBPass.Checked = config.GuestBook.Pass;
        }

        private void WriteGuestBookConfigXML()
        {
            var config = CMSConfig.Instance();
            config.GuestBook.PageSize = int.Parse(this.txtGBPageSize.Text);
            config.GuestBook.Name = this.txtGuestBookName.Text;
            config.GuestBook.ShowGB = this.cbkShowGB.Checked;
            config.GuestBook.Pass = this.cbkGBPass.Checked;
            config.Save(config);
        }

        #endregion
    }
}